import axios from "axios";

const http = axios.create({
    baseURL: "http://localhost:3000/",
    timeout: 3000
})

// Add a request interceptor
http.interceptors.request.use(function (config) {
    // Do something before request is sent

    // 验证用户是否登录
    /*let admin = sessionStorage.getItem("admin");
    if(admin == null || admin == ''){
        //需要重新登录
        router.push('/login')
        ElMessage.error('账号登录状态已经过期，请重新登录')
    }*/

    console.log("请求拦截")
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});

// Add a response interceptor
http.interceptors.response.use(function (response) {
    // Do something with response data
    //处理响应数据多一层的问题
    return response.data;
}, function (error) {
    // Do something with response error
    return Promise.reject(error);
});

export default http;